package com.activeMq.entity;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.io.IOException;

public class Consumer1 {
    public static void main(String[] args) throws JMSException, IOException {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
        factory.setTrustAllPackages(true);
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("tx_queue");
        MessageConsumer consumer = session.createConsumer(queue);
        //监听
        consumer.setMessageListener(new TextMessageLestener());
        System.in.read();
        //ObjectMessage message = (ObjectMessage) consumer.receive();
        //TextMessage message = (TextMessage) consumer.receive();
        //Person text = (Person) message.getObject();
        //System.out.println(text.toString());
        consumer.close();
        session.close();
        connection.close();
    }
}
